package com.itheima.canal.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    //队列
    public static final String AD_UPDATE_QUEUE="ad_update_queue";
    public static final String SEARCH_UPDATE_QUEUE="search_update_queue";
    public static final String SEARCH_DEL_QUEUE="search_del_queue";

    //交换机
    public static final String GOODS_UP_EXCHANGE="goods_up_exchange";
    public static final String GOODS_DOWN_EXCHANGE="goods_down_exchange";

    @Bean
    public  Queue AD_UPDATE_QUEUE(){
        return QueueBuilder.durable(AD_UPDATE_QUEUE).build();
    }

    @Bean(SEARCH_UPDATE_QUEUE)
    public Queue SEARCH_UPDATE_QUEUE(){
        return QueueBuilder.durable(RabbitMQConfig.SEARCH_UPDATE_QUEUE).build();
    }

    @Bean(SEARCH_DEL_QUEUE)
    public Queue SEARCH_DEL_QUEUE(){
        return QueueBuilder.durable(RabbitMQConfig.SEARCH_DEL_QUEUE).build();
    }

    @Bean(GOODS_UP_EXCHANGE)
    public Exchange GOODS_UP_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(RabbitMQConfig.GOODS_UP_EXCHANGE).durable(true).build();
    }
    @Bean(GOODS_DOWN_EXCHANGE)
    public Exchange GOODS_DOWN_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(RabbitMQConfig.GOODS_DOWN_EXCHANGE).durable(true).build();
    }

    @Bean
    public Binding  goods_up_exchange_Binding(@Qualifier(SEARCH_UPDATE_QUEUE)Queue queue,@Qualifier(GOODS_UP_EXCHANGE)Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }

    @Bean
    public Binding  GOODS_DOWN_EXCHANGE_BINDING(@Qualifier(SEARCH_DEL_QUEUE)Queue queue,@Qualifier(GOODS_DOWN_EXCHANGE)Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }
}

